#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;

// __thread声明线程局部存储变量
__thread int num = 0;

void *run1(void *args)
{
    while (1)
    {
        cout << "修改num:" << num++ << endl;
        sleep(1);
    }
}

void *run2(void *args)
{
    while (1)
    {
        cout << "num:" << num << endl;
        sleep(1);
    }
}

int main()
{
    pthread_t tid1, tid2;
    pthread_create(&tid1, nullptr, run1, nullptr);
    pthread_create(&tid2, nullptr, run2, nullptr);

    while (1)
    {
    }
}